package cn.fighter3.controller;

import cn.fighter3.entity.node.*;
import cn.fighter3.result.Result;
import cn.fighter3.service.impl.BookService;
import cn.fighter3.service.impl.PeopleService;
import cn.fighter3.service.node.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/api/people")
public class PeopleController {
    @Autowired
    PeopleService peopleService;
    @Autowired
    CnbookDao cnbookDao;
    @Autowired
    FgbookDao fgbookDao;
    @Autowired
    MscbookDao mscbookDao;
    @Autowired
    MulbookDao mulbookDao;
    @Autowired
    PapbookDao papbookDao;
    @Autowired
    PerbookDao perbookDao;
    @Autowired
    PeopleDao peopleDao;
    @GetMapping("/cypher/{cypher}")
    public List<Object> findByCypher(@PathVariable("cypher") String cypher){
        System.out.println("cypher查询语句是："+cypher);
        List<Object> objectList=peopleService.findByCypher(cypher);
        return objectList;
    }

    @GetMapping("/all")
    public Result findAll(){
        List<People> peopleList = peopleService.findAll();
        List<CustomNode> customNodes = new ArrayList<>();
        int i=0;
        for (People peo : peopleList){
            i++;
            customNodes.add(new CustomNode(peo.getAuthorName(), 1,peo,0));//peopleDao.countpeo(peo.getAuthorId())
            if(i>25)
                break;

        }
        return (new Result(200,"hello",customNodes));
    }

    @GetMapping("/all2")
    public Result all(){
        List<People> peopleList = peopleService.all();
        List<CustomNode> customNodes = new ArrayList<>();
        //List<People> people11= (List<People>) peopleList.keySet();
        for(People people1:peopleList){
            //People people1 = peopleService.findByAuthorName(people.getAuthorName());
            String name= people1.getAuthorName();
            System.out.println(name);
            customNodes.add(new CustomNode(people1.getAuthorName(), 1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
        }
//        List<Result> results = new ArrayList<>();
//        for(CustomNode customNode:customNodes){
//            results.add(new Result(200,"hello",customNode));
//        }

        return (new Result(200,"hello",customNodes));
    }

    @GetMapping("/count/{id}")
    public Result count(@PathVariable("id") String id){
        return (new Result(200,"hello",peopleService.count(id)));
    }
    //    @GetMapping("/{name}/{age}")
//    public CustomNode findByAuthorName(@PathVariable("name") String name ,@PathVariable("age") String age){
    @GetMapping("/{name}")
    public Result findByAuthorName(@PathVariable("name") String name){
        System.out.println(name);
        //System.out.println(age);
        List<People> people = peopleService.findByAuthorName(name);
        System.out.println(people.size());
        List<CustomNode> customNodes=new ArrayList<>();
        for (People people1:people){
            System.out.println(people1.getAuthorName());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
        }
        return (new Result(200,"hello",customNodes));
//        List<CustomNode> res = new ArrayList<>();
//        for(People peo : people){
//            res.add(new CustomNode(peo.getAuthorName(),1,peo));
//        }
    }


    @GetMapping("/query/{relationship}/{name}")
    public Result getAuthorByName(@PathVariable("relationship") String rel,@PathVariable("name") String name){
        List<People> people=peopleService.findByAuthorName(name);
        List<CustomNode> customNodes = new ArrayList<>();
        Set<Book> cnbookSet = new HashSet<>();
        for (People people1:people){
            Set<CustomNode> bookSet = peopleService.getBooksByRelationship(people1,rel);
//            for (Book book:bookSet){
//                cnbookSet.add(book);
//            }
            for (CustomNode customNode:bookSet){
                customNodes.add(customNode);
            }
        }
        //Set<Book> cnbookSet = peopleService.getBooksByRelationship(people,rel);

//        for(Book book : cnbookSet){
//            customNodes.add(new CustomNode(book.getTitle(),  2,book));
//        }
        //return customNodes;
        return (new Result(200,"hello",customNodes));
    }

//    @GetMapping("/query/{relationship}/{id}")
//    public List<CustomNode> getAuthorById(@PathVariable("relationship") String rel,@PathVariable("id") String id){
//        //List<People> people=peopleService.findByAuthorName(name);
//        Optional<People> people=peopleService.findByAuthorId(id);
//        List<CustomNode> customNodes = new ArrayList<>();
////        Set<Book> cnbookSet = new HashSet<>();
////        for (People people1:people){
////            Set<Book> bookSet = peopleService.getBooksByRelationship(people1,rel);
////            for (Book book:bookSet){
////                cnbookSet.add(book);
////            }
////        }
//        if(people.isPresent()){
//            People people1=people.get();
//            Set<Book> cnbookSet = peopleService.getBooksByRelationship(people1,rel);
//            for(Book book : cnbookSet){
//                customNodes.add(new CustomNode(book.getTitle(),  2,book));
//            }
//        }
//        return customNodes;
//    }



//    @GetMapping("/aa/{relationship}/{name}")
//    public List<CustomNode> aa(@PathVariable("relationship") String rel,@PathVariable("name") String name){
//        return null;
//    }

    //    @GetMapping("/cypher")
//    public

    //由书找人--Authorof

    @GetMapping("/book/people/{id}")
    public Result findByfromid1(@PathVariable("id") String id){
        //System.out.println("successin");
        List<People> peopleList=peopleService.findByfromid1(id);
        List<CustomNode> customNodes=new ArrayList<>();
        for (People people1:peopleList){
            System.out.println(people1.getAuthorName());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
        }
        Result results =new Result(200,"hello",customNodes);
        return results;
    }

    //由书找人--Lend
    @GetMapping("/book/people2/{id}")
    public Result findByfromid2(@PathVariable("id") String id){
        //System.out.println("successin");
        List<People> peopleList=peopleService.findByfromid11(id);
        List<CustomNode> customNodes=new ArrayList<>();
        for (People people1:peopleList){
            System.out.println(people1.getAuthorName());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
        }
        Result results =new Result(200,"hello",customNodes);
        return results;
    }


    //查询--按照节点id
    @GetMapping("findid/{id}")
    public Result findByAuthorId(@PathVariable("id") String id) {
        Optional<People> optionalPeople = peopleService.findByAuthorId(id);
        if(optionalPeople.isPresent()){
            //return optionalPeople.get();
            People people=optionalPeople.get();
            return (new Result(200,"hello",people));//new CustomNode(people.getAuthorName(),1,people,peopleDao.countpeo(people.getAuthorId())
        }
        else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }

    //增加
//    @GetMapping("add/{people}")
//    public People create(@PathVariable("people") People people){
//        return peopleService.create(people);
//    }

    @GetMapping("add/{name}/{id}")
    public Result create(@PathVariable("name") String name,@PathVariable("id") String id){
        People people= peopleService.create(name,id);
        //return new CustomNode(name,1,people);
        return (new Result(200,"hello",new CustomNode(name,1,people,0)));//peopleDao.countpeo(people.getAuthorId())
    }

    //删除
    @GetMapping("delete/{id}")
    public Result deleteByAuthorId(@PathVariable("id") String id){
        //System.out.println(id);
        //Long idd = Long.valueOf(123);
        peopleService.deleteByAuthorId(id);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/deletename/{name}")
    public Result deleteByAuthorName(@PathVariable("name") String name){
        //System.out.println(id);
        //Long idd = Long.valueOf(123);
        peopleService.deleteByAuthorName(name);
        return new Result(200,"删除成功",null);
    }



    //更新
    @GetMapping("update/{id}/{name}")
    public Result updateByNode(@PathVariable("id") String id,@PathVariable("name") String name){
        People people= peopleService.updateByNode(id,name);
        //return new CustomNode(people.getAuthorName(),1,people);
        return (new Result(200,"hello",new CustomNode(people.getAuthorName(),1,people,0)));//peopleDao.countpeo(people.getAuthorId())
    }


//    @GetMapping("/findid")
//    public People findByAuthorId(@RequestParam(value = "id") String id) {
//        Optional<People> optionalPeople = peopleService.findByAuthorId(id);
//        if(optionalPeople.isPresent()){
//            return optionalPeople.get();
//        }
//        else{
//            return null;
//        }
//    }
    //访问路径的区别   http://localhost:9999/api/people/findid?id=300015



    @Autowired
    BookService bookService;
    @GetMapping("/cnbook/add/{fromId}/{toId}")
    //public Authorof1 addAuthor1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
    public Result addAuthor1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        Optional<People> people = peopleService.findByAuthorId(toId);
        Cnbook cnbook = bookService.findByBookId1(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(people.isPresent()) {
            People people1 = people.get();
            people1.addcn(cnbook);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(cnbook.getTitle(),2,cnbook,0));//cnbookDao.countcn(cnbook.getBookId())
//            System.out.println("people1");
//            System.out.println(people1.getAuthorName());
//
//            for (Cnbook cnb:people1.getAuthorCnbook()){
//                System.out.println(cnb.getBookId()+"+"+cnb.getTitle());
//            }

            //System.out.println("cnbook");
            //System.out.println(cnbook.getTitle());
            //System.out.println("testssss");
            //System.out.println(people1.getAuthorCnbook());
            ////People peopletest=peopleService.save(people1);
            peopleService.addAuthor1(fromId, toId);
            //return (new CustomNode(people1.getAuthorName(),1,people1));
            return (new Result(200,"hello",customNodes));
            //Optional<People> people2 = peopleService.findByAuthorId(toId);
            //People people22=people2.get();
//            System.out.println("peopletest");
//            System.out.println(peopletest.getAuthorName());
//            int i=0;
//            for (Cnbook cnb:peopletest.getAuthorCnbook()){
//                i++;
//                System.out.println(i+" " +cnb.getBookId()+"+"+cnb.getTitle());
//            }
            //return peopleService.addAuthor1(fromId, toId);
        }
        else
            //return null;
            return (new Result(200,"hello",null));
    }
    @GetMapping("/cnbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId1(fromId, toId);
        return new Result(200,"删除成功",null);
    }



    @GetMapping("/cnbook/add2/{fromId}/{toId}/{time}")
    //public Authorof1 addAuthor1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
    public Result addLend1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId,@PathVariable("time") String time){
        Optional<People> people = peopleService.findByAuthorId(fromId);
        Cnbook cnbook = bookService.findByBookId1(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(people.isPresent()) {
            People people1 = people.get();
            people1.addcn2(cnbook);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(cnbook.getTitle(),2,cnbook,0));//cnbookDao.countcn(cnbook.getBookId())
            peopleService.addLend1(fromId, toId,time);
            return (new Result(200,"hello",customNodes));
        }
        else
            return (new Result(200,"hello",null));
    }
    @GetMapping("/cnbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId11(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId11(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/cnbook/update2/{fromId}/{toId}/{time}")
    //public Authorof1 addAuthor1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
    public Result updateLend1(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId,@PathVariable("time") String time){
        Optional<People> people = peopleService.findByAuthorId(fromId);
        Cnbook cnbook = bookService.findByBookId1(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(people.isPresent()) {
            People people1 = people.get();
            //people1.addcn2(cnbook);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(cnbook.getTitle(),2,cnbook,0));//cnbookDao.countcn(cnbook.getBookId())
            peopleService.updateLend1(fromId, toId,time);
            return (new Result(200,"hello",customNodes));
        }
        else
            return (new Result(200,"hello",null));
    }





    @GetMapping("/fgbook/add/{fromId}/{toId}")
    public Result addAuthor2(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId){
        Fgbook from=bookService.findByBookId2(fromId);
        Optional<People> to=peopleService.findByAuthorId(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addfg(from);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),3,from,0));//fgbookDao.countfg(from.getBookId())
            peopleService.addAuthor2(from,to.get());
            //return peopleService.addAuthor2(from,to.get());
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/fgbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId2(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId2(fromId, toId);
        return new Result(200,"删除成功",null);
    }


    @GetMapping("/fgbook/add2/{fromId}/{toId}/{time}")
    public Result addLend2(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Fgbook from=bookService.findByBookId2(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addfg2(from);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),3,from,0));//fgbookDao.countfg(from.getBookId())
            peopleService.addLend2(fromId,toId,time);
            //return peopleService.addAuthor2(from,to.get());
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/fgbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId22(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId22(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/fgbook/update2/{fromId}/{toId}/{time}")
    public Result updateLend2(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Fgbook from=bookService.findByBookId2(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            //people1.addfg2(from);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),3,from,0));//fgbookDao.countfg(from.getBookId())
            peopleService.updateLend2(fromId,toId,time);
            //return peopleService.addAuthor2(from,to.get());
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }


    @GetMapping("/mscbook/add/{fromId}/{toId}")
    public Result addAuthor3(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId){
        Mscbook from=bookService.findByBookId3(fromId);
        Optional<People> to=peopleService.findByAuthorId(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addmsc(from);
            peopleService.addAuthor3(from,to.get());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),4,from,0));//mscbookDao.countmsc(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/mscbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId3(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId3(fromId, toId);
        return new Result(200,"删除成功",null);
    }


    @GetMapping("/mscbook/add2/{fromId}/{toId}/{time}")
    public Result addLend3(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Mscbook from=bookService.findByBookId3(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addmsc2(from);
            //peopleService.addLend3(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),4,from,0));//mscbookDao.countmsc(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.addLend3(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/mscbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId33(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId33(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/mscbook/update2/{fromId}/{toId}/{time}")
    public Result updateLend3(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Mscbook from=bookService.findByBookId3(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            //people1.addmsc2(from);
            //peopleService.addLend3(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),4,from,0));//mscbookDao.countmsc(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.updateLend3(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }


    @GetMapping("/mulbook/add/{fromId}/{toId}")
    public Result addAuthor4(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId){
        Mulbook from=bookService.findByBookId4(fromId);
        Optional<People> to=peopleService.findByAuthorId(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addmul(from);
            peopleService.addAuthor4(from,to.get());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),5,from,0));//mulbookDao.countmul(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor4(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor4(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/mulbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId4(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId4(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/mulbook/add2/{fromId}/{toId}/{time}")
    public Result addLend4(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Mulbook from=bookService.findByBookId4(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addmul2(from);
            //peopleService.addLend4(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),5,from,0));//mulbookDao.countmul(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.addLend4(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor4(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor4(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/mulbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId44(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        System.out.println("delete2"+fromId+toId);
        peopleService.deleteByNodeId44(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/mulbook/update2/{fromId}/{toId}/{time}")
    public Result updateLend4(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Mulbook from=bookService.findByBookId4(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
           //people1.addmul2(from);
            //peopleService.addLend4(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),5,from,0));//mulbookDao.countmul(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.updateLend4(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor4(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor4(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }



    @GetMapping("/papbook/add/{fromId}/{toId}")
    public Result addAuthor5(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId){
        Papbook from=bookService.findByBookId5(fromId);
        Optional<People> to=peopleService.findByAuthorId(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addpap(from);
            peopleService.addAuthor5(from,to.get());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),6,from,0));//papbookDao.countpap(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor5(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor5(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/papbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId5(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId5(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/papbook/add2/{fromId}/{toId}/{time}")
    public Result addLend5(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Papbook from=bookService.findByBookId5(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            people1.addpap2(from);
            //peopleService.addLend5(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),6,from,0));//papbookDao.countpap(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.addLend5(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor5(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor5(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/papbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId55(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId55(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/papbook/update2/{fromId}/{toId}/{time}")
    public Result updateLend5(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Papbook from=bookService.findByBookId5(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            People people1=to.get();
            //people1.addpap2(from);
            //peopleService.addLend5(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),6,from,0));//papbookDao.countpap(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.updateLend5(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
            //return peopleService.addAuthor5(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor5(from,to.get())));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }


    @GetMapping("/perbook/add/{fromId}/{toId}")
    public Result addAuthor6(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId){
        Perbook from=bookService.findByBookId6(fromId);
        Optional<People> to=peopleService.findByAuthorId(toId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            //return peopleService.addAuthor6(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor6(from,to.get())));
            People people1=to.get();
            people1.addper(from);
            peopleService.addAuthor6(from,to.get());
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),7,from,0));//perbookDao.countper(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/perbook/delete/{fromId}/{toId}")
    public Result deleteByNodeId6(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId6(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/perbook/add2/{fromId}/{toId}/{time}")
    public Result addLend6(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Perbook from=bookService.findByBookId6(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            //return peopleService.addAuthor6(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor6(from,to.get())));
            People people1=to.get();
            people1.addper2(from);
            //People peopletest=peopleService.save(people1);
            //peopleService.addLend6(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),7,from,0));//perbookDao.countper(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.addLend6(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }
    @GetMapping("/perbook/delete2/{fromId}/{toId}")
    public Result deleteByNodeId66(@PathVariable("fromId") String fromId,@PathVariable("toId") String toId){
        peopleService.deleteByNodeId66(fromId, toId);
        return new Result(200,"删除成功",null);
    }
    @GetMapping("/perbook/update2/{fromId}/{toId}/{time}")
    public Result updateLend6(@PathVariable("fromId") String fromId, @PathVariable("toId") String toId, @PathVariable("time") String time){
        Perbook from=bookService.findByBookId6(toId);
        Optional<People> to=peopleService.findByAuthorId(fromId);
        List<CustomNode> customNodes = new ArrayList<>();
        if(to.isPresent()){
            //return peopleService.addAuthor6(from,to.get());
            //return (new Result(200,"hello",peopleService.addAuthor6(from,to.get())));
            People people1=to.get();
            //people1.addper2(from);
            //People peopletest=peopleService.save(people1);
            //peopleService.addLend6(fromId,toId,time);
            customNodes.add(new CustomNode(people1.getAuthorName(),1,people1,0));//peopleDao.countpeo(people1.getAuthorId())
            customNodes.add(new CustomNode(from.getTitle(),7,from,0));//perbookDao.countper(from.getBookId())
            //return peopleService.addAuthor3(from,to.get());
            peopleService.updateLend6(fromId,toId,time);
            return (new Result(200,"hello",customNodes));
        }else{
            //return null;
            return (new Result(200,"hello",null));
        }
    }

}

